/**
 * FileName: LoadRidePointConfiguration
 * Author:   Leopold
 * Date:     2018/9/19 16:47
 * Description:
 * History:
 */
package cn.mcsys.worker.core.conf;

import java.awt.geom.Point2D;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class LoadRidePointConfiguration {

    public static final String XIANGHZOU = "xiangzhou";
    public static final String TIYUZHONGXIN = "tiyuzhongxin";
    public static final String JIUZHOUCHENG = "jiuzhoucheng";
    public static final String JIUZHOUGUANG = "jiuzhouguang";
    public static final String CHENGGUI = "chenggui";
    public static final String QIANSHAN = "qianshan";
    public static final String HUAFASHANGDOU = "huafashangdou";
    public static final String DOUMEN = "doumen";
    public static final String SAICHECHANG = "saichechang";
    public static final String HANGZHANGUAN = "hangzhanguan";

    public static Map<String,List<Point2D.Double>> ridePointMap = new HashMap<>();
    public static Map<String,List<Point2D.Double>> hangzhanguan = new HashMap<>();

    static {
        InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("ride-point-lon-lat.properties");

        Properties properties = new Properties();

        try {
            properties.load(in);
//        航展一号专线：香洲公交总站
            List<Point2D.Double> xiangzhou = createridePoint2D(properties, XIANGHZOU);
//        航展二号专线：体育中心东门
            List<Point2D.Double> tiyuzhongxin = createridePoint2D(properties, TIYUZHONGXIN);
//        航展三号专线：九洲城
            List<Point2D.Double> jiuzhoucheng = createridePoint2D(properties, JIUZHOUCHENG);
//        航展四号专线：九洲港
            List<Point2D.Double> jiuzhouguang = createridePoint2D(properties, JIUZHOUGUANG);
//        航展五号专线：城轨珠海站
            List<Point2D.Double> chenggui = createridePoint2D(properties, CHENGGUI);
//        航展六号专线：前山枢纽站
            List<Point2D.Double> qianshan = createridePoint2D(properties, QIANSHAN);
//        航展七号专线：华发商都
            List<Point2D.Double> huafashangdou = createridePoint2D(properties, HUAFASHANGDOU);
//        航展八号专线：斗门汽车客运站
            List<Point2D.Double> doumen = createridePoint2D(properties, DOUMEN);
//        航展九号专线：国际赛车场
            List<Point2D.Double> saichechang = createridePoint2D(properties, SAICHECHANG);
//        航展核心区域
            List<Point2D.Double> zhanguan = createridePoint2D(properties,HANGZHANGUAN);

            ridePointMap.put(XIANGHZOU,xiangzhou);
            ridePointMap.put(TIYUZHONGXIN,tiyuzhongxin);
            ridePointMap.put(JIUZHOUCHENG,jiuzhoucheng);
            ridePointMap.put(JIUZHOUGUANG,jiuzhouguang);
            ridePointMap.put(CHENGGUI,chenggui);
            ridePointMap.put(QIANSHAN,qianshan);
            ridePointMap.put(HUAFASHANGDOU,huafashangdou);
            ridePointMap.put(DOUMEN,doumen);
            ridePointMap.put(SAICHECHANG,saichechang);
            hangzhanguan.put(HANGZHANGUAN,zhanguan);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static Double[] parseLonLat(String lonlat){
        String[] lls = lonlat.split(",");
        Double[] lld = new Double[2];
        for (int i = 0; i < lls.length-1; i++) {
            lld[i] = Double.valueOf(lls[i]);
        }
        return lld;
    }

    private static List<Point2D.Double> createridePoint2D(Properties properties,String pointName){
        List<Point2D.Double> points = new ArrayList<>();
        Double[] point1 = parseLonLat(properties.getProperty(pointName+"-1"));
        Double[] point2 = parseLonLat(properties.getProperty(pointName+"-2"));
        Double[] point3 = parseLonLat(properties.getProperty(pointName+"-3"));
        Double[] point4 = parseLonLat(properties.getProperty(pointName+"-4"));
        points.add(new Point2D.Double(point1[0],point1[1]));
        points.add(new Point2D.Double(point2[0],point2[1]));
        points.add(new Point2D.Double(point3[0],point3[1]));
        points.add(new Point2D.Double(point4[0],point4[1]));
        return points;
    }
}
